﻿// /////////////////////////////////// 
//  
//  
//      WiseLink CCF2.0 
//     (c)Copyright 2001-2010 WiseLink Xiaojun (David) Chen 
//        Authored and Owned Xiaojun (David) Chen 
//        All Right Reserved
//  
// /////////////////////////////////// 

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Infrastructure.Extension;
using Infrastructure.Log;

namespace ZICModel.Fault
{
    public class HeaderHandler
    {
        private FaultBase currentFault;
        public HeaderHandler(FaultBase fault) 
        {
            currentFault = fault;
            currentFault.FaultHeader = new Header();
            
        }


        public bool Process()
        {
            currentFault.FaultHeader.SrcFaultId = currentFault.OriginalFault.id;
            currentFault.FaultHeader.EquipmentId = currentFault.OriginalFault.EquipmentId;
            currentFault.FaultHeader.GPSTime = currentFault.OriginalFault.GpsTime;
            currentFault.FaultHeader.ReceiveTime = currentFault.OriginalFault.InsTime;
            currentFault.FaultHeader.Idc = currentFault.OriginalFault.SimNum;
            currentFault.FaultHeader.Ids = currentFault.OriginalFault.ids;
            currentFault.FaultHeader.Mileage = currentFault.OriginalFault.PropertyData.Substring(0, 6).HexString2Int();
            
            int mainFaultCount;
            
            mainFaultCount = currentFault.OriginalFault.PropertyData.Substring(6, 2).HexString2Int();
            currentFault.FaultHeader.MainFaultCount = mainFaultCount;
            currentFault.FaultHeader.IsValid = true;
            CallLogger.LogMessage(typeof(HeaderHandler),string.Format("******Start to process ZIS Message AnchiId={0}*********",currentFault.FaultHeader.SrcFaultId));
            CallLogger.LogMessage(typeof(HeaderHandler), string.Format("Header: Mileage: SrcString {0}, Integer {1},MainFaultCount:{2}",
                                                            currentFault.OriginalFault.PropertyData.Substring(0, 6),
                                                            currentFault.FaultHeader.Mileage,
                                                            mainFaultCount));
            return true;

        }
    }
}
